package com.gzhryc.shared_device.bxscn.core.protocol.v1.msg;

import com.gzhryc.common.secruity.CRC16;

import java.io.Serializable;

public class CNRequest implements Serializable{

	private static final long serialVersionUID = 1L;
	
	public final static String CMD = "CN";
	
	private String cmd = CMD;
	private String deviceSn;
	private String imsi;
	private String version;
	private Integer rssi;
	private String iccid;
	
	public CNRequest() {}
	
	public CNRequest(BaseMessage baseMessage) {
		String[] data = baseMessage.getData();

		if(data != null) {
			if(data.length >= 1) {
				this.deviceSn = data[0];
			}
			if(data.length >= 2) {
				this.imsi = data[1];
			}
			if(data.length >= 3) {
				this.version = data[2];
			}
			if(data.length >= 4) {
				this.rssi = Integer.valueOf(data[3]);
			}
			if(data.length >= 5) {
				this.iccid = data[4];
			}
		}
	}

	public String getCmd() {
		return cmd;
	}
	
	public void setCmd(String cmd) {
		this.cmd = cmd;
	}
	
	public String getDeviceSn() {
		return deviceSn;
	}

	public void setDeviceSn(String deviceSn) {
		this.deviceSn = deviceSn;
	}

	public String getImsi() {
		return imsi;
	}

	public void setImsi(String imsi) {
		this.imsi = imsi;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public Integer getRssi() {
		return rssi;
	}

	public void setRssi(Integer rssi) {
		this.rssi = rssi;
	}

	public String getIccid() {
		return iccid;
	}

	public void setIccid(String iccid) {
		this.iccid = iccid;
	}
	
	public String getData() {
		String data = cmd+","+deviceSn+","+imsi+","+version+","+rssi+","+iccid;
		return data;
	}

	public String getMessage() {
		String data = getData();
		String crc16 = CRC16.get((data+","+ BaseMessage.MESSAGE_KEY).getBytes());
		return "{"+data+","+crc16+"}";
	}

}
